﻿using System.IO;
using Mh.SpriteFontPlus;
using Microsoft.Xna.Framework.Graphics;

namespace ms.Util
{
    public static class SpriteFontEX
    {
        public static float fontSize = 16f;
        public static SpriteFont InitChineseFont(float fontPielHeight, bool w = false)
        {
            try
            {
#if WINDOWS
                var realPath = @"F:\Program Files (x86)\MapleStory";
#else
			var realPath = "/storage/emulated/0/Download/";
#endif

                var fontPath = w ? "msyh.ttf" : "msyhbd.ttf";
                var fontBakeResult = TtfFontBaker.Bake
                (
                File.ReadAllBytes(Path.Combine(realPath, fontPath)),
                fontPielHeight,
                1024 * 3,
                1024 * 3,
                new[]
                {
                    new CharacterRange(' '),
                    CharacterRange.BasicLatin,
                    CharacterRange.Chinese,
                    CharacterRange.ChineseSupplement,
                    CharacterRange.ChineseSymbol0,
                    CharacterRange.ChineseSymbol1,
                    CharacterRange.ChineseSymbol2,
                    CharacterRange.ChineseSymbol3,
                    CharacterRange.ChineseSymbol4,
                    CharacterRange.ChineseSymbol5,
                    CharacterRange.ChineseSymbol6,
                    CharacterRange.ChineseSymbol7,
                    CharacterRange.ChineseSymbol8,
                    CharacterRange.ChineseSymbol9,
                    CharacterRange.ChineseSymbol10,
                    CharacterRange.ChineseSymbol11,
                    CharacterRange.ChineseSymbol12,
                    CharacterRange.ChineseSymbol13,
                    CharacterRange.ChineseSymbol14,
                    CharacterRange.ChineseSymbol15,
                    CharacterRange.ChineseSymbol16,
                    CharacterRange.ChineseSymbol17,
                    CharacterRange.ChineseSymbol18,
                    CharacterRange.ChineseSymbol19,
                    CharacterRange.ChineseSymbol20,
                    CharacterRange.ChineseSymbol21,
                    CharacterRange.ChineseSymbol22,
                    CharacterRange.ChineseSymbol23,
                    CharacterRange.ChineseSymbol24,
                    CharacterRange.ChineseSymbol25,
                    CharacterRange.ChineseSymbol26,
                    CharacterRange.ChineseSymbol27,
                    CharacterRange.ChineseSymbol28,
                    });
                return fontBakeResult.CreateSpriteFont(GameUtil.get().GraphicsDevice);

            }
            catch (System.Exception ex)
            {
                AppDebug.Log($"{ex.Message}");
                return null;
            }
        }
    }
}